package com.mokairui.http;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpServerCodec;

/**
 * @Description com.sunshine.http
 * @Author Mokairui
 * @Since 2022/1/11
 */
public class SimpleHttpChannelInitializer extends ChannelInitializer<SocketChannel> {

    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        // 向管道加入处理器
        // 得到管道
        ChannelPipeline pipeline = ch.pipeline();
        // 加入一个 netty 提供的 httpServerCodec codec => [coder - decoder]
        pipeline.addLast("MyHttpServerCodec", new HttpServerCodec());
        // 添加一个自定义 handler
        pipeline.addLast("SimpleHttpHandler", new SimpleHttpHandler());
    }

}
